<template>
  <Card title="非遗列表">
    <Card :bordered="false">
      <DatePicker type="datetimerange" format="yyyy-MM-dd HH:mm:ss" placeholder="请选择开始结束时间" style="width: 15.5vw" v-model="dateLimit"></DatePicker>
      <Button type="primary" @click="query" style="margin-left: 15px">查询</Button>
    </Card>

    <Table border stripe ref="selection" size="small" :columns="columns" :data="nowData">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">查看</Button>
        <Button type="error" size="small" @click="remove(row)">删除</Button>
        <Modal
          v-model="modal1"
          title="提示"
          @on-ok="okDel"
          @on-cancel="cancel">
          <p>确定要删除此信息吗?删除后将不能恢复</p>
        </Modal>
      </template>
    </Table>
    <Page :total="dataCount" :page-size="queryAdminCuHeritageBO.size" @on-change="changePage" @on-page-size-change="_nowPageSize"
          show-total show-sizer show-elevator/>
  </Card>
</template>

<script>
export default {
  name: 'heritage-list',
  data () {
    return {
      delRow: {},
      modal1: false,
      dataCount: 0,
      nowData: [],
      dateLimit: [],
      queryAdminCuHeritageBO: {
        startDate: '',
        endDate: '',
        current: 1,
        size: 10
      },
      columns: [
        {
          title: '序号',
          key: 'cuHeritageId'
        },
        {
          title: '标题',
          key: 'cuHeritageTitle'
        }, {
          title: '发布时间',
          key: 'cuHeritageDate'
        }, {
          title: '发布者信息',
          key: 'cuHeritagePublisher'
        }, {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ]
    }
  },
  methods: {
    _nowPageSize (index) {
      // 实时获取当前需要显示的条数
      this.queryAdminCuHeritageBO.size = index
    },
    changePage (index) {
      this.queryAdminCuHeritageBO.current = index
      this.query()
    },
    okDel () {
      this.$axios_supermall.post('/cu-heritage/deleteId', this.delRow.cuHeritageId).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.info('删除成功')
          this.query()
        } else {
          this.$Message.info(resp.data.msg)
        }
      })
    },
    cancel () {
      this.$Message.info('取消删除')
    },
    show (row) {
      this.$router.push('/heritage/heritage_add/' + row.cuHeritageId)
    },
    remove (row) {
      this.delRow = row
      this.modal1 = true
    },
    query () {
      this.queryAdminCuHeritageBO.startDate = this.dateLimit[0]
      this.queryAdminCuHeritageBO.endDate = this.dateLimit[1]
      this.$Loading.start()
      this.$axios_supermall.post('/cu-heritage/queryPage', this.queryAdminCuHeritageBO).then(resp => {
        if (resp.data.code == 0) {
          let data = resp.data.data
          this.nowData = data.records
          this.queryAdminCuHeritageBO.current = data.current
          this.queryAdminCuHeritageBO.size = data.size
          this.dataCount = data.total
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    }
  },
  mounted () {
    this.query()
  }
}
</script>

<style scoped>

</style>
